﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BLL
{
    public class PhanCongBLL
    {
        
        public List<PhanCong> GetAllPhanCong()
        {
            using (var cc = new ChamCongEntities())
            {
                return cc.PhanCongs.Include("CongNhan").Include("CongDoan").Include("CongNhan1").ToList<PhanCong>();
            }
        }
        public PhanCong GetPhanCongById(int id)
        {
            using (var cc = new ChamCongEntities())
            {
                return cc.PhanCongs.Where(pc => pc.PhanCongId == id).FirstOrDefault();
            }
        }
        public void InsertPhanCong(PhanCong phanCong)
        {
          
            using (var cc = new ChamCongEntities())
            {
                cc.Entry(phanCong).State = EntityState.Added;                
                cc.SaveChanges();
            }
        }
        public void UpdatePhanCong(PhanCong phanCong)
        {
            using (var cc = new ChamCongEntities())
            {
                cc.Entry(phanCong).State = EntityState.Modified;
                cc.SaveChanges();
            }
        }
        public void DeletePhanCong(PhanCong phanCong)
        {
            using (var cc = new ChamCongEntities())
            {
                cc.Entry(phanCong).State = EntityState.Deleted;
                cc.SaveChanges();
            }
        }
        public List<PhanCong> GetPhanCongByMonthYear(int thang=0,int nam=0)
        {
            using (var cc = new ChamCongEntities())
            {
                return cc.PhanCongs.Include("CongNhan").Include("CongDoan").Where(pc => pc.Thang == thang && pc.Nam == nam).ToList<PhanCong>();
            }
        }
        public PhanCong GetPhanCongByMonthYearIdNhanVien(int thang = 0, int nam = 0,int manhanvien=0)
        {
            using (var cc = new ChamCongEntities())
            {
                return cc.PhanCongs.Include("CongNhan").Include("CongDoan").Where(pc => pc.Thang == thang && pc.Nam == nam&&pc.CongNhanId==manhanvien).FirstOrDefault();
            }
        }
    }
}
